/**
 * 
 * @fileOverview View control for the edit device page.
 * @author jmanero
 * 
 */

/** @ignore */
exports.callback = function(req, res, next) {
	try {
		model.Device.findOne({
			_id : req.params.device
		}, function(e, device) {
			model.Message.error(e);
			if (device) {
				model.Port.find({
					device : device._id
				}, function(e, ports) {
					model.Message.error(e);
					res.render('editDevice.jade', {
						pageTitle : 'Device Configuration',
						device : device,
						ports : ports,
						pretty : true
					});
				});
			} else {
				model.Message.warn('Unable to find device ' + req.params.device);
				res.render('message.jade', {
					pageTitle : 'Message',
					type : 'Warning',
					date : Date.now(),
					message : 'Unable to find device ' + req.params.device
				});
			}
		});
	} catch (e) {
		model.Message.error(e);
		res.render('error.jade', {
			pageTitle : 'Error',
			e : e,
			date : Date.now()
		});
	}
};

/** @ignore */
exports.path = '/devices/:device';

/** @ignore */
exports.method = 'get';
